<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">      
</head>
<body>
	<%@ page import="com.bardsoftware.foronuvolo.data.Discussion"
		 import="java.lang.NullPointerException"
 	%>
 	<% 	
	 	String userId = request.getParameter("UserId");
	 	String id = request.getParameter("id");
	 	String like = request.getParameter("like");
	 	Long discussionID = Long.valueOf(id);
	 	Long value = Long.valueOf(like);
	 	Discussion d = Discussion.find(discussionID);
	 	if(d == null) {
	 		return;
	 	}
	 	if(!d.getUsersWhoVoted().contains(userId)) {
	 		d.addRating(value);
	 		d.addNewVoter(userId);
 	%>
 		<p> Thank you for your vote!</p>
	<%}
 	else { %>
 		<p>We're sorry, but you have already voted for this discussion.</p>
 	<%
 	}
 	d.save();
 %>
 	<br>
 	Click <a href="/">here</a> to return back to discussion. <br>
 	Or <a href="/">here</a> to go to the main page.
</body>
</html>